package com.example.lirisheng.springbootfinalexperiment.controller;

import com.example.lirisheng.springbootfinalexperiment.entity.RecordTemperature;
import com.example.lirisheng.springbootfinalexperiment.entity.Users;
import com.example.lirisheng.springbootfinalexperiment.entity1.RecordTempEntity;
import com.example.lirisheng.springbootfinalexperiment.entity1.ResidentEntity;
import com.example.lirisheng.springbootfinalexperiment.repositories.PersonInformationRepository;
import com.example.lirisheng.springbootfinalexperiment.repositories.UsersRepository;
import com.example.lirisheng.springbootfinalexperiment.service.CheService;
import com.example.lirisheng.springbootfinalexperiment.util.RespBean;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.LinkedHashMap;
import java.util.Map;

@RestController
@RequestMapping("/weiChe")
public class WeiCheController {

    @Autowired
    PersonInformationRepository personInformationRepository;
    @Autowired
    CheService cheService;
    @Autowired
    UsersRepository usersRepository;
    protected Logger logger= LoggerFactory.getLogger(WeiCheController.class);

    @ApiOperation(value = "添加住户的温度信息", notes = "添加住户的温度信息")
    @PostMapping("/addTemp")
    public RespBean addTem(@Valid  @RequestParam("res_open_id")String resOpenId, RecordTemperature recordTemperature){

        if (logger.isDebugEnabled()){
            logger.debug("addTemp");
        }

        //如果合法,则进行添加
        try{
            cheService.addTemp(resOpenId,recordTemperature);
            return RespBean.ok("体温添加成功");
        }catch (Exception exception){
            System.out.println("message:"+exception.getMessage());
            return RespBean.error("体温添加失败");
        }

    }

    @ApiOperation(value = "检查人员绑定openId", notes = "检查人员绑定openId")
    @PostMapping("/bandOpenId")
    public RespBean  registerResident(@RequestBody Users users){

        if(logger.isDebugEnabled()){
            logger.debug("residentEntity:"+users);
        }
        try {
            return cheService.bandOpenId(users);
        }catch (Exception exception){
            System.out.println("message:"+exception.getMessage());
            return RespBean.error("绑定失败");
        }
    }

}
